package qeb.handheldmedical.helper;

import qeb.handheldmedical.model.Phone;
import android.content.Context;
import android.telephony.TelephonyManager;

public class PhoneInfo {
    public TelephonyManager telephonemanager;
    
    public Phone phone=new Phone();
    
    private String IMSI;
    private Context ctx;
    /**
     * 获取手机国际识别码IMEI
     * */
    public  PhoneInfo(Context context){
        ctx=context;
        telephonemanager=(TelephonyManager)context
                .getSystemService(Context.TELEPHONY_SERVICE);
    }
    
    /**
     * 获取手机号码 
     * */
    public String getNativePhoneNumber(){
       
       String nativephonenumber=null;
       nativephonenumber=telephonemanager.getLine1Number();
        
       return nativephonenumber;        
    }
    
    public void getPhoneInfo(){
    	TelephonyManager tm=(TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
    
        phone.Deviceid=tm.getDeviceId();
        //phone.Devicesoftwareversion=tm.getDeviceSoftwareVersion();
        //phone.Line1number=tm.getLine1Number();
        //phone.Networkcountryiso=tm.getNetworkCountryIso();
        //phone.Networkoperator=tm.getNetworkOperator();
        //phone.Networkoperatorname=tm.getNetworkOperatorName().toString();
        //phone.Networktype=String.valueOf(tm.getNetworkType());
        //phone.Phonetype=String.valueOf(tm.getPhoneType());
        //phone.Simcountryiso=tm.getSimCountryIso();
        //phone.Simoperator=tm.getSimOperator();
        //phone.Simoperatorname=tm.getSimOperatorName();
        //phone.Simserialnumber=tm.getSimSerialNumber();
        //phone.Simstate=String.valueOf(tm.getSimState());
        //phone.Subscriberid=tm.getSubscriberId();
        //phone.Voicemailnumber=tm.getVoiceMailNumber();
    }
    
    /**
     * 获取手机服务商信息
     *  
     * */
    public String  getProvidersName(){
        String providerName=null;
        try{
            IMSI=telephonemanager.getSubscriberId();
            //IMSI前面三位460是国家号码，其次的两位是运营商代号，00、02是中国移动，01是联通，03是电信。
            System.out.print("IMSI是："+IMSI);
            if(IMSI.startsWith("46000")||IMSI.startsWith("46002")){
                providerName="中国移动";
            }else if(IMSI.startsWith("46001")){
                providerName="中国联通";
            }else if(IMSI.startsWith("46003")){
                providerName="中国电信";
        }
            
        }catch(Exception e){
            e.printStackTrace();
        }
        return providerName;
 
}
    /**
     * 获取手机信息
     * */
    public String getPhoneInfoToString(){
       
        TelephonyManager tm=(TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
        StringBuilder sb=new StringBuilder();
    
        sb.append("\nDeviceID(IMEI)"+tm.getDeviceId());
        sb.append("\nDeviceSoftwareVersion:"+tm.getDeviceSoftwareVersion());
        sb.append("\ngetLine1Number:"+tm.getLine1Number());
        sb.append("\nNetworkCountryIso:"+tm.getNetworkCountryIso());
        sb.append("\nNetworkOperator:"+tm.getNetworkOperator());
        sb.append("\nNetworkOperatorName:"+tm.getNetworkOperatorName());
        sb.append("\nNetworkType:"+tm.getNetworkType());
        sb.append("\nPhoneType:"+tm.getPhoneType());
        sb.append("\nSimCountryIso:"+tm.getSimCountryIso());
        sb.append("\nSimOperator:"+tm.getSimOperator());
        sb.append("\nSimOperatorName:"+tm.getSimOperatorName());
        sb.append("\nSimSerialNumber:"+tm.getSimSerialNumber());
        sb.append("\ngetSimState:"+tm.getSimState());
        sb.append("\nSubscriberId:"+tm.getSubscriberId());
        sb.append("\nVoiceMailNumber:"+tm.getVoiceMailNumber());
     
        return sb.toString();
                
    }            
}